package com.sl.eurekaserver.controller;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sl.eurekaserver.entity.User;
import com.sl.eurekaserver.servicce.UserService;

@RestController
public class HelloController {

	@Autowired
	private UserService userService;

	@RequestMapping(value = "hello", method = RequestMethod.GET)
	public String index() {
		return "Hello Word";
	}

	@RequestMapping(value = "/hellol", method = RequestMethod.GET)
	public String hello(@RequestParam String name) {
		return "Hello " + name;
	}

	@RequestMapping(value = "/users/{userName}", method = RequestMethod.GET)
	public User getUser(@PathVariable("userName") String userName) {
		return userService.getUserByUserName(userName);
	}

	@RequestMapping(value = "/users", method = RequestMethod.GET)
	public List<User> getUsers(String userNames) {
		return userService.getUsers(Arrays.asList(StringUtils.split(userNames,
				",")));
	}
}
